/* 
 * Copyright (c) 2012 JSquirrelEngine
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in 
 * the Software without restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
 * Software, and to permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */

package org.jsquirrel.rendering.LWJGLimpl;

import org.lwjgl.opengl.GL11;



public class LWJGL_OrthoCamera extends LWJGL_Camera {

	//*********************************************************************************************
	// INSTANCE ATTRIBUTES
	//*********************************************************************************************
	
	private float xLeft, xRight;
	
	private float yTop, yBottom;
	
	private float zNear, zFar;
	
	private float rotationAngle;
	
	/**
	 * rotation axis
	 */
	private float rX, rY;
	
	
	//*********************************************************************************************
	// CONSTRUCTOR
	//*********************************************************************************************
	
	public LWJGL_OrthoCamera() {
		
		xLeft = 0;
		xRight = 1;
		yBottom = 0;
		yTop = 1;
		zNear = 0;
		zFar = 1;
		
		rX = 0;
		rY = 0;
		
		rotationAngle = 0;
		
	}
	
	
	//*********************************************************************************************
	// PUBLIC METHODS
	//*********************************************************************************************
	
	@Override
	public final void prepare() {
		
		GL11.glMatrixMode(GL11.GL_PROJECTION);
			GL11.glLoadIdentity();
			GL11.glOrtho(xLeft, xRight, yBottom, yTop, zNear, zFar);
		
		
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
			GL11.glLoadIdentity();
			GL11.glTranslatef(rX, rY, 0);
			GL11.glRotatef(rotationAngle, 0, 0, 1);
			
	}

	public final void setRectangle(float xLeft, float xRight, float yBottom, float yTop) {
		
		this.xLeft = xLeft;
		this.xRight = xRight;
		this.yBottom = yBottom;
		this.yTop = yTop;
	}
	
	public final void setRotationAxis(float x, float y) {
		rX = x;
		rY = y;
	}
	
	public final float getRotationAxisX() {
		return rX;
	}
	
	public final float getRotationAxisY() {
		return rY;
	}
	
	public final void setRotationAngle(float angle) {
		this.rotationAngle = angle;
	}
	
	public final float getRotationAngle() {
		return rotationAngle;
	}
	
	public final void setZInterval(float zNear, float zFar) {
		this.zNear = zNear;
		this.zFar = zFar;
	}
}
